package com.sweet.jpa.domain;

import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * 排序规则，仿自org.springframework.data.domain.Sort
 *
 * @author limi
 * @create 2018-03-19-16:48
 */
@Getter
public class Sort {
    /**
     * 排序字段
     */
    private final List<Order> orders;

    public Sort(Order... orders) {
        this(Arrays.asList(orders));
    }

    public Sort(List<Order> orders) {
        this.orders = orders;
    }

    /**
     * 排序方向
     */
    public enum Direction {
        ASC,
        DESC
    }

    /**
     * 排序字段
     */
    @Getter
    public static class Order implements Serializable {
        private final String property;
        private final Direction direction;

        private Order() {
            this.property = null;
            this.direction = null;
        }

        public Order(final String property, final Direction direction) {
            this.property = property;
            this.direction = direction;
        }
    }
}
